"use strict";
cc._RF.push(module, '16c0aXA7r9Ayow81Bpaf47E', 'LotteryElement');
// scripts/LotteryElement.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var r,
    s,
    l = t("CarConstant"),
    c = t("GlobalUserData"),
    d = t("BoxGetView"),
    h = t("ConfirmRewardPanel"),
    p = t("HallConstant"),
    u = t("HallScene"),
    f = t("BroadCastMessage"),
    m = t("Util"),
    _ = t("Bounce"),
    y = t("Particle"),
    g = t("Global"),
    v = t("BaseStorage");

(function (t) {
  t[t.coin = 0] = "coin", t[t.power = 1] = "power", t[t.diamond = 2] = "diamond", t[t.box = 3] = "box", t[t.car = 4] = "car";
})(r || (r = {})), function (t) {
  t[t.grad1 = 0] = "grad1", t[t.grad2 = 1] = "grad2", t[t.grad3 = 2] = "grad3", t[t.grad4 = 3] = "grad4", t[t.grad5 = 4] = "grad5", t[t.grad6 = 5] = "grad6", t[t.grad7 = 6] = "grad7", t[t.grad8 = 7] = "grad8", t[t.grad9 = 8] = "grad9", t[t.grad10 = 9] = "grad10";
}(s || (s = {}));

var C = cc._decorator,
    b = C.ccclass,
    w = C.property,
    S = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.bonusType = r.coin, e.grades = s.grad1, e.choosedNode = null, e.valueLabel = null, e.received = null, e.titleSpr = null, e.iconSpr = null, e.pfb_box = null, e.iconPrefab = null, e.iconFrame = null, e.titleFrames = [], e.iconFrames = [], e._mrg = null, e.proList = [[.26, .26, .26, .05, .05, .05, .025, .025, .02, 0], [.12, .12, .12, .13, .13, .14, .08, .08, .08, 0], [.025, .025, .02, .21, .21, .21, .1, .1, .1, 0], [.025, .025, .02, .17, .17, .17, .14, .14, .14, 0], [0, 0, 0, .04, .04, .02, .2, .2, .2, .2]], e.value = 0, e.obj = {
      a: 0
    }, e;
  }

  return n(e, t), e.prototype.init = function (t) {
    this._mrg = t;
  }, e.prototype.onLoad = function () {
    this.bonusType == r.car && v.BaseStorage.getInt(g.BaseStorageKey.LuckyCar, 0) && (this.bonusType = r.diamond, this.value = 1e3), this.choosedNode.active = this.received.active = !1;
    var t = Number(this.bonusType);
    this.iconSpr.spriteFrame = this.iconFrames[t], this.iconFrame = this.iconFrames[t];
    var e = this.iconSpr.node.width / this.iconSpr.node.height;
    this.iconSpr.node.width > 81 && (this.iconSpr.node.width = 81, this.iconSpr.node.height = 81 / e);
  }, e.prototype.onEnable = function () {
    this.node.scale = 0, cc.tween(this.node).to(.5, {
      scale: 1
    }, {
      easing: "elasticOut"
    }).start(), this.valueLabel.node.addComponent(_["default"]).init(1, this.value);
  }, Object.defineProperty(e.prototype, "IsSelected", {
    set: function set(t) {
      var e;
      e = t ? 1.05 : 1, cc.tween(this.node).to(.1, {
        scale: e
      }).start(), this.choosedNode.active = t;
    },
    enumerable: !1,
    configurable: !0
  }), Object.defineProperty(e.prototype, "IsReceived", {
    set: function set() {},
    enumerable: !1,
    configurable: !0
  }), e.prototype.getGift = function () {
    var t = this;
    cc.tween(this.choosedNode).to(.1, {
      opacity: 0
    }).to(.1, {
      opacity: 255
    }).to(.1, {
      opacity: 0
    }).to(.1, {
      opacity: 255
    }).call(function () {
      switch (t.IsReceived = !0, t.IsSelected = !1, t.bonusType) {
        case r.coin:
          m.Util.showConfirmPanel([{
            type: h.rewardType.gold,
            num: t.value
          }], function () {
            c["default"].saveGoldData(!0, t.value), cc.find("Canvas").getComponent(u["default"]).onSetOwnGold(!0), t.action(t.iconPrefab, "frame_gold");
          }, !0, function () {
            c["default"].saveGoldData(!0, 2 * t.value), cc.find("Canvas").getComponent(u["default"]).onSetOwnGold(!0), t.action(t.iconPrefab, "frame_gold");
          });
          break;

        case r.power:
          m.Util.showConfirmPanel([{
            type: h.rewardType.vit,
            num: t.value
          }], function () {
            c["default"].saveVitData(!0, t.value), cc.find("Canvas").getComponent(u["default"]).onSetOwnVit(!0), t.action(t.iconPrefab, "frame_vit");
          }, !0, function () {
            c["default"].saveVitData(!0, 2 * t.value), cc.find("Canvas").getComponent(u["default"]).onSetOwnVit(!0), t.action(t.iconPrefab, "frame_vit");
          });
          break;

        case r.diamond:
          m.Util.showConfirmPanel([{
            type: h.rewardType.diamond,
            num: t.value
          }], function () {
            c["default"].saveDiamondData(!0, t.value), cc.find("Canvas").getComponent(u["default"]).onSetOwnDiamond(!0), t.action(t.iconPrefab, "frame_diamond");
          }, !0, function () {
            c["default"].saveDiamondData(!0, 2 * t.value), cc.find("Canvas").getComponent(u["default"]).onSetOwnDiamond(!0), t.action(t.iconPrefab, "frame_diamond");
          });
          break;

        case r.box:
          m.Util.showConfirmPanel([{
            type: h.rewardType.legendBox,
            num: t.value
          }], function () {
            var e = cc.instantiate(t.pfb_box);
            cc.find("Canvas").addChild(e, 100), e.getComponent(d["default"]).showOpenBoxView(d.Box_Type.senior, cc.find("Canvas").getComponent(u["default"]));
          }, !0, function () {
            var e = cc.instantiate(t.pfb_box);
            cc.find("Canvas").addChild(e, 100), e.getComponent(d["default"]).showOpenBoxView(d.Box_Type.senior, cc.find("Canvas").getComponent(u["default"]));
            var o = cc.instantiate(t.pfb_box);
            cc.find("Canvas").addChild(o, 99), o.getComponent(d["default"]).showOpenBoxView(d.Box_Type.senior, cc.find("Canvas").getComponent(u["default"]));
          });
          break;

        case r.car:
          m.Util.initCustomCar([{
            bodyId: "body02",
            wheel0Id: "wheel04",
            wheel1Id: "wheel04",
            weapon0Id: l.Weapon_ID.Grapeshot,
            tool0Id: l.Tools_ID.Thruster
          }], c["default"].freeCarData, 1, 4), t._mrg && t._mrg.backHall();
      }
    }).start();
  }, e.prototype.getLuckyLevel = function () {
    var t = v.BaseStorage.getInt(g.BaseStorageKey.Lucky, 0);
    return t <= 20 ? 0 : t > 20 && t <= 50 ? 1 : t > 50 && t <= 80 ? 2 : t > 80 && t < 100 ? 3 : t >= 100 ? 4 : void 0;
  }, e.prototype.getProbability = function () {
    return this.proList[this.getLuckyLevel()][Number(this.grades)];
  }, e.prototype.action = function (t, e) {
    f["default"].getInstance().SendMessage(p.Broadcast_Func.Audio, p.Audio_ID.get_gold);

    for (var o = 0; o < 20; o++) {
      var i = cc.instantiate(t),
          n = cc.find("Canvas").getChildByName(e).convertToWorldSpaceAR(cc.Vec2.ZERO),
          a = this.node.getChildByName("icon").convertToNodeSpaceAR(n),
          r = this.node.getChildByName("icon").getPosition();
      i.setPosition(r), i.parent = this.node.getChildByName("icon"), i.getComponent(y["default"]).init(m.Util.getRandomInt(0, 360), m.Util.getRandomInt(200, 400), a, this.iconFrame);
    }
  }, a([w({
    type: cc.Enum(r)
  })], e.prototype, "bonusType", void 0), a([w({
    type: cc.Enum(s)
  })], e.prototype, "grades", void 0), a([w(cc.Node)], e.prototype, "choosedNode", void 0), a([w(cc.Label)], e.prototype, "valueLabel", void 0), a([w(cc.Node)], e.prototype, "received", void 0), a([w(cc.Sprite)], e.prototype, "titleSpr", void 0), a([w(cc.Sprite)], e.prototype, "iconSpr", void 0), a([w(cc.Prefab)], e.prototype, "pfb_box", void 0), a([w(cc.Prefab)], e.prototype, "iconPrefab", void 0), a([w(cc.SpriteFrame)], e.prototype, "iconFrame", void 0), a([w(cc.SpriteFrame)], e.prototype, "titleFrames", void 0), a([w(cc.SpriteFrame)], e.prototype, "iconFrames", void 0), a([w(cc.Float)], e.prototype, "value", void 0), a([b], e);
}(cc.Component);

o["default"] = S;

cc._RF.pop();